package com.baseLearn.learn.spring;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.*;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

/**
 * springBean的声明周期
 */
@Component
@Slf4j
public class SpringBeanLearn implements BeanNameAware, BeanFactoryAware, InitializingBean, ApplicationContextAware, DisposableBean {

    /**
     * BeanNameAware中的方法
     *
     * @param s
     */
    @Override
    public void setBeanName(String s) {
        log.info("setBeanName方法,参数s=" + s);
    }

    /**
     * BeanFactoryAware中的方法
     *
     * @param beanFactory
     * @throws BeansException
     */
    @Override
    public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
        log.info("setBeanFactory,参数beanFactory=" + beanFactory.toString());
    }


    /**
     * InitializingBean中的方法
     *
     * @throws Exception
     */
    @Override
    public void afterPropertiesSet() throws Exception {
        log.info("afterPropertiesSet方法");
    }

    /**
     * ApplicationContextAware中的方法
     *
     * @param applicationContext
     * @throws BeansException
     */
    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        log.info("applicationContext方法" + applicationContext.toString());
    }

    @Override
    public void destroy() throws Exception {
        log.info("destroy方法");
    }
}
